package day3.HomeWork;

/**
 * ClassName：Productor
 *
 * @Author：小鱼
 * @Create：2025-08-20 20:26
 */
public class Productor extends Thread{
    private Clerk clerk = new Clerk();

    public Productor(String name, Clerk clerk) {
        super(name);
        this.clerk = clerk;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (clerk) {
                while (clerk.staff >= 20) {
                    try {
                        clerk.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                clerk.staff++;
                System.out.println(this.getName() + "生产了：" + clerk.staff);
                clerk.notifyAll();
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
